package flexcommon.tests.validators
{
	import flexcommon.validators.AdvancedCreditCardValidator;
	
	import flexunit.framework.Assert;
	import flexunit.framework.TestCase;
	
	import mx.events.ValidationResultEvent;

	/**
	 * @private
	 */
	public class TestAdvancedCreditCardValidator extends TestCase
	{
		private var val:AdvancedCreditCardValidator;
    private var obj:Object; // represents a TextInput control in real scenario
		
		public function TestAdvancedCreditCardValidator(methodName:String=null)
		{
			super(methodName);
		}
		
		public override function setUp():void 
		{
      obj = new Object();
      val = new AdvancedCreditCardValidator();
      val.source = obj; 
      val.property = "text";
    }
		
		public function testValidVI():void 
		{
      try {
        obj.text = "4111111111111111";
        val.cardBrand = "VI";
      	
      	var res:ValidationResultEvent = val.validate( obj, true );
      	Assert.assertEquals( "valid", res.type );
      }
      catch( e:Error ) {
      	trace( "testValidVI >> " + e.getStackTrace() );
      	fail( "testValidVI failed: " + e.message );
      }
    }
	    
    public function testInvalidVI():void 
		{
      try {
        obj.text = "41AB111111111111";
        val.cardBrand = "VI";
      	
      	var res:ValidationResultEvent = val.validate( obj, true );
      	Assert.assertEquals( "invalid", res.type );
      }
      catch( e:Error ) {
      	trace( "testInvalidVI >> " + e.getStackTrace() );
      	fail( "testInvalidVI failed: " + e.message );	        	
      }
    }
	    
    public function testInvalidMC():void 
		{
      try {
        obj.text = "5023111122223333";
        val.cardBrand = "MC";
      	
      	var res:ValidationResultEvent = val.validate( obj, true );
      	Assert.assertEquals( "invalid", res.type );
      }
      catch( e:Error ) {
      	trace( "testInvalidMC >> " + e.getStackTrace() );
      	fail( "testInvalidMC failed: " + e.message );	        	
      }
    }		
	}
}